<%@page contentType="text/html;charset=UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="javabean.*"%>
<%@page import="javabean.book.*"%>
<%@page import="javabean.user.*"%>
<%
	request.setCharacterEncoding("utf-8");
	String type = request.getParameter("type");
	String keyword = request.getParameter("keyword");
	List<Book> all = null;
	int count = 0 ,limitSize=10;
	try{
		if(type!=null && !"".equals(type)){
			all = Factory.getBookDAOInstance().queryAllBookByType(type,1,limitSize) ;
			count = Factory.getBookDAOInstance().queryCountBookByType(type);
			Factory.getBookDAOInstance().updateBookTagReadCount(type);
		}else{
			if(keyword!=null && !"".equals(keyword)){
				count = Factory.getBookDAOInstance().queryCountBookByLike(keyword) ;
				all = Factory.getBookDAOInstance().queryAllBookByLike(keyword,1,limitSize) ;
			}else{
				count = Factory.getBookDAOInstance().queryCountBookByLike("") ;
				all = Factory.getBookDAOInstance().queryAllBookByLike("",1,limitSize) ;
			}
		}
	}
	catch(Exception e){}	
	//传给ajax的值
	String hiddenType = type==null?"":type;
	String hiddenKeyword = keyword==null?"":keyword;
%>
<div class="container bc-container">
	<input type="hidden" value="<%=hiddenType %>" class="hidden-type"/>
	<input type="hidden" value="<%=hiddenKeyword %>" class="hidden-keyword"/>
	<div class="content-top">
	    <p>当前图书：<label class="label label-info">
	    	<%if(type!=null && !"".equals(type)){%>
	    		<%=type %>
	    	<%}else if(keyword!=null && !"".equals(keyword)){ %>
	    		搜索 “ <%=keyword %> ” 的结果
	    	<%}else{ %>
	    		全部
	    	<%} %>
	    </label>
	    <span class="count-tips">已载入 <span class="loaded-count"><%=all.size() %></span> 条 / 共 <span class="all-count"><%=count %></span> 条</span>
	    </p>
	</div>
	<div class="content-main">
		<div class="bd-content">
		<%
			if(all.isEmpty()){ 
				if(type!=null && !"".equals(type)){
		%>
			<div class="alert alert-warning">
				此分类还没有图书哦！我来<a href="/bookcrossing/book/add?type=<%=type %>"> 添加 </a>^_^
			</div>
		<%
				}else if(keyword!=null && !"".equals(keyword)){
		%>
			<div class="alert alert-warning">
				没有搜到任何结果哦！我来<a href="/bookcrossing/book/add"> 添加 </a>^_^
			</div>
		<%
				}	
			}else{ 
				Iterator<Book> iter = all.iterator() ;
				while(iter.hasNext()){
					Book book = (Book)iter.next();
					long  bid = book.getBid() ;
					String isbn = book.getIsbn() ;
					String bname = book.getBname() ;
					String author = book.getAuthor() ;
					String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
					String introduce = (book.getOther()==null)?"":book.getOther() ;
		%>
			<div class="bd-c-list">
			    <div class="book-pic">
			        <a href="/bookcrossing/book?bid=<%=bid %>">
			             <img src="/bookcrossing/img/book/<%=picurl %>" alt="<%=bname %>"/>
			        </a>
			    </div>
			    <p class="book-title">
			    	<a href="/bookcrossing/book?bid=<%=bid %>" title="<%=bname %>"><%=bname %></a>
			    </p>
			    <p class="book-author"><%=author %></p>
			    <p class="book-introduce">
			    	<%
						byte[] s = introduce.getBytes();
						if(s.length>180){
					%>
						<%=new String(s,0,180)+"..."%>
					<%}else{ %>
						<%=introduce %>
					<%} %>
			    </p>
			</div>
		<%}} %>
		</div>
		<div class="right">
      		<div >
	       		<div class="right-top"></div>
	       		<div class="right-content-wrap">
	        		<div class="right-content">
	        			<p class="right-c-title">分类查看</p>
	        			<table class="right-c-bd">
	        			<%
	        				List<BookTag> bookTag = null ;
		        			try{
		        				bookTag = Factory.getBookDAOInstance().queryAllBookTag();
		        			}
		        			catch(Exception e){}
		        			String[] labelStyle = {"label-primary","label-warning","label-info","label-success"};
		        			Random r = new Random();	//随机数对象
		        			boolean isEnd = false;
		        			Iterator<BookTag> tagIter = bookTag.iterator() ;
		        			while(tagIter.hasNext()){
	        			%>
	        				<tr>
	        			<%
	        					for(int i=0; i<3; i++){
	        						if(tagIter.hasNext()){
	        							BookTag book_tag = (BookTag)tagIter.next();
	        							String tagName = book_tag.getTagname();
	        			%>
	        					<td><a href="/bookcrossing/?type=<%=tagName %>" class="label <%=labelStyle[i] %>"><%=tagName %></a></td>

	        			<%
	        						}else if(!isEnd){
	        							isEnd = true;
	        			%>
	        					<td><a href="/bookcrossing/" class="label label-default">全部</a></td>
	        			<% 
	        						}
	        					}
	        			%>
	        				</tr>
		        		<%
		        			}
		        			if(!isEnd){
		        		%>
		        			<tr><td><a href="/bookcrossing/" class="label label-default">全部</a></td></tr>
		        		<%
		        			}
		        		%>
	        			</table>
	        		</div>
	        	</div>
      			<div class="right-bottom"></div>
      		</div>
      	</div>
      	<div class="toTop-wrap">
       		<a href="javascript:;" id="toTop" title="返回顶部"></a>
       	</div>
	</div>
	<div class="content-bottom">
		<div class="loading-content">
			<i class="loading-pic1 rel-top-3"></i>
			<span class="loading-text">loading...</span>
		</div>
		<div class="loading-btn">
			出错啦，请点击 <a href="javascript:;" id="loading-btn"> 重试 </a>
		</div>
	</div>
</div>







